package artibella.ui 
{
	import artibella.IDisposable;
	
	import flash.display.InteractiveObject;
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;

	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class ContextMenuFeeder implements IDisposable
	{
		
		private var _mc:InteractiveObject; 
		private var _cm:ContextMenu;
		

		public function ContextMenuFeeder( mc:InteractiveObject, v:Boolean = true  )
		{	
			_mc = mc;
			
			_init( v );
		}

		private function _init( v:Boolean ):void
		{
			_cm = new ContextMenu();
			if( !v ) _cm.hideBuiltInItems();
			
			_mc.contextMenu = _cm;				
		}
		
		///////  A J O U T

		public function addItem( s:String, f:Function = null ):ContextMenuItem
		{
			var item:ContextMenuItem = new ContextMenuItem( s );
			
			if( f == null ){
				item.enabled = false;	
			} else {
				item.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, f );
			}
			
			_cm.customItems.push( item );
			
			return item;	
		}
		
		//----- IDisposable
		
		public function dispose():void 
		{
			_mc = null;
			
			_cm.customItems = null;
			_cm = null;
		}
	}
 }
		